package com.lemo.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableDemo {
	
	public static void main(String[] args) {
		CallableI callableI = new CallableI();
		FutureTask<Integer> futureTask = new FutureTask<>(callableI);
		new Thread(futureTask).start();
		try {
			Integer result = futureTask.get();
			System.out.println(result);
			System.out.println("-----------------");
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
	}
}


class CallableI implements Callable<Integer>{

	@Override
	public Integer call() throws Exception {
		
		Integer sum = 0 ;
		
		for (int i = 0; i <= 10000; i++) {
			sum += i;
		}
		return sum;
	}
	
}